package com.test;

import com.pojo.Customer;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerByNameAndJobsTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Customer customer = new Customer();
        //customer.setUsername("jack");
        //customer.setJobs("teacher");
        List<Customer> customers = sqlSession.selectList("com.findCustomerByNameAndJobs", customer);
        for (Customer c : customers) {
            for (Customer cust : customers) {
                System.out.println(cust);
            }
            sqlSession.commit();
            sqlSession.close();
        }
        @Test
        public void updateCustomerByTest(){
            SqlSession SqlSession = MyBatisUtils.getSqlSession();
            Customer customer1 = new Customer();
            customer.setId(3);
            customer.setPhone("133111111234");
            customer.setUsername("jack");
            int rows = sqlSession.update("com.mapper.CustomerMapper.updateByPrimaryKeySelective", customer);
            if (rows > 0) {
                System.out.println("您成功修改了" + rows + "条数据！");
            } else {
                System.out.println("执行操作失败！！！");
            }
            sqlSession.commit();
            sqlSession.close();
        }
        @Test
        public void findByArrayTest () {
            SqlSession SqlSession = MyBatisUtils.getSqlSession();
            Integer[] roleIds = {2, 3};
            List<com.mapper.customer> Customers = sqlSession.
                    selectList("com.mapper.CustomerMapper.findByArray", roleIds);
            for (Customer Customer : customers) {
                System.out.println(customer);
            }
            sqlSession.close();
        }
    }
}
